﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.FileProviders;

namespace FileProviderDemo.Controllers
{
    public class FileProviderController : Controller
    {
        private readonly IFileProvider _fileProvider;

        public FileProviderController(IFileProvider fileProvider)
        {
            _fileProvider = fileProvider;
        }

        [Route("fileProvider/index")]
        public IActionResult Index()
        {
            var contents = _fileProvider.GetDirectoryContents(string.Empty);

            return View(contents);
        }

        [Route("fileProvider/index2")]
        public IActionResult Index2()
        {

            #region EmbeddedFileProvider如何获取嵌套资源里的内容?
            //var content = string.Empty;

            //var assembly = Assembly.GetEntryAssembly();

            //var stream = assembly.GetManifestResourceStream("FileProviderDemo.Views.Home.Privacy.cshtml");

            //using (var streamReader = new StreamReader(stream))
            //{
            //    content = streamReader.ReadToEnd();
            //}
            #endregion


            return View();
        }

    }
}